package com.zsj.service_user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zsj.service_user.entity.AppOrder;
import com.zsj.service_user.mapper.AppOrderMapper;
import com.zsj.service_user.service.AppOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsj
 * @since 2022-05-03
 */
@Service
public class AppOrderServiceImpl extends ServiceImpl<AppOrderMapper, AppOrder> implements AppOrderService {


    @Autowired
    private AppOrderService appOrderService;


    /**
     * 根据账号名获取订单
     *
     * @param name
     * @return
     */
    @Override
    public List<AppOrder> getAllByName(String name, String status) {
        QueryWrapper<AppOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_belongto_user",name);
        queryWrapper.eq("order_status",status);
        return appOrderService.list(queryWrapper);
    }

    //添加商品订单信息
    @Override
    public boolean saveOrder(AppOrder order) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        order.setOrderCreateTime(format.format(new Date()));
        return appOrderService.save(order);
    }
}
